package ws;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import org.orm.PersistentException;

import com.google.gson.Gson;

import SOAPVO.LogSOAPVO;
import SOAPVO.PrecioSOAPVO;

public class LogSOA {
	/**
	 * 
	 * @param valor
	 * @return
	 */
	public String agregarLog(String valor){
		
		String json=null;
		Collection<LogSOAPVO> logColecion = new ArrayList<LogSOAPVO>();
		orm.Tcl_log[] ormLog;
		
		// instancia DAO factory
		orm.DAOFactory lDAOFactory = orm.DAOFactory.getDAOFactory();

		try {

			ormLog = lDAOFactory.getTcl_logDAO().listTcl_logByQuery(null, null);
			//System.out.println(ormLog[0].getLog_nombre());
		
			int length = ormLog.length;
			if (length == 0) {// si no se encontraron registros
				json = "No se ha encontrado ningun registro";
			} else {// si se encontraron registros
				for (int i = 0; i < length; i++) {
					LogSOAPVO objeto = LogSOAPVO.crearLogSOAPVO(ormLog[i]);
					logColecion.add(objeto);
				}// fin guardando resultados
				// Envia los datos al json
				Gson gson = new Gson();
				json = gson.toJson(logColecion);
			}
		} catch (PersistentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return json;
	}

}
